﻿
using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using BE;

namespace DA
{
    public class daDetalleMateriales
    {
        public static DataTable Obtener(beDetalleMaterial oBE)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_ConsultarDetalleMateriales");
            sqlClient.AddInParameter(dbCmd, "@IDDetalleMateriales", DbType.Int32, oBE.IDDetalleMateriales);
            sqlClient.AddInParameter(dbCmd, "@IDReporteGuardia", DbType.Int32, oBE.IDReporteGuardia);
            sqlClient.AddInParameter(dbCmd, "@IDItem", DbType.Int32, oBE.IDItem);
            sqlClient.AddInParameter(dbCmd, "@CantidadInternas", DbType.Single, oBE.CantidadInterna);
            sqlClient.AddInParameter(dbCmd, "@CantidadCliente", DbType.Single, oBE.CantidadCliente);
            return sqlClient.ExecuteDataSet(dbCmd).Tables[0];
        }

        public static Int32 Registrar(beDetalleMaterial oBE)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_RegistrarDetalleMateriales");
            sqlClient.AddInParameter(dbCmd, "@IDReporteGuardia", DbType.Int32, oBE.IDReporteGuardia);
            sqlClient.AddInParameter(dbCmd, "@IDItem", DbType.Int32, oBE.IDItem);
            sqlClient.AddInParameter(dbCmd, "@CantidadInternas", DbType.Single, oBE.CantidadInterna);
            sqlClient.AddInParameter(dbCmd, "@CantidadCliente", DbType.Single, oBE.CantidadCliente);
            return Convert.ToInt32(sqlClient.ExecuteScalar(dbCmd));
        }

        public static Int32 Eliminar(beDetalleMaterial oBE)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_EliminarDetalleMateriales");
            sqlClient.AddInParameter(dbCmd, "@IDDetalleMateriales", DbType.Int32, oBE.IDDetalleMateriales);

            return Convert.ToInt32(sqlClient.ExecuteScalar(dbCmd));
            //sqlClient.ExecuteNonQuery(dbCmd);
        }
        public static Int32 Modificar(beDetalleMaterial oBE)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_ModificarDetalleMateriales");
            sqlClient.AddInParameter(dbCmd, "@IDDetalleMateriales", DbType.Int32, oBE.IDDetalleMateriales);
            sqlClient.AddInParameter(dbCmd, "@IDReporteGuardia", DbType.Int32, oBE.IDReporteGuardia);
            sqlClient.AddInParameter(dbCmd, "@IDItem", DbType.Int32, oBE.IDItem);
            sqlClient.AddInParameter(dbCmd, "@CantidadInternas", DbType.Single, oBE.CantidadInterna);
            sqlClient.AddInParameter(dbCmd, "@CantidadCliente", DbType.Single, oBE.CantidadCliente);
            return Convert.ToInt32(sqlClient.ExecuteScalar(dbCmd));
        }

    }
}
